// 判断用户是否登录
var username = getCookie('username')
if(!username){
    layer.msg('非法访问！',{
        icon: 2,
        time: 2000
    }, function(){
        location.href = 'login.html?callback='+location.href
    })
}else{
    // 发送请求获取当前用户信息
    $.ajax({
        url: 'http://localhost:8888/users/info?id='+getCookie('userId'),
        headers: {
            authorization: localStorage.getItem('token') || ''
        }
    }).then(res => {
        console.log(res);
        if(res.code === 1){
            var html = `
                <tr>
                    <td>用户名：</td>
                    <td>${res.info.username} </td>
                </tr>
                <tr>
                    <td>昵称：</td>
                    <td>${res.info.nickname} </td>
                </tr>
                <tr>
                    <td>身份：</td>
                    <td>${res.info.identity} </td>
                </tr>
                <tr>
                    <td>年龄：</td>
                    <td>${res.info.age === '' ? '未知' : res.info.age} </td>
                </tr>
                <tr>
                    <td>性别：</td>
                    <td>${res.info.gender === '' ? '未知' : res.info.gender} </td>
                </tr> 
            `
            $('.rightcontent tbody').html(html)
        }

    })
}